package com.job.liushuang.HomeWork0715;

import java.util.Arrays;

/**
 * @author Liushuang
 * @version 1.0
 * @since 2022-07-15 20:21:39
 */
public class StringConstructer {
    public static void main(String[] args) {
        byte[] bytes = {97, 98, 99, 100, 101, 102};
        String s1 = new String(bytes);//按照默认字符集unicode来转换字节整数的码值到字符
        System.out.println(s1);

        String s2 = new String(bytes, 1, 3);//打印bcd    offset偏移
        System.out.println(s2);

        char[] chars = {'A', '我', 66, '!', '=', '他'};
        System.out.println(new String(chars));
        String s3 = new String(chars, 3, 3);
        System.out.println(s3);

        //字符串-字节/字符数组
        String name = "夏日一个雪糕";//UTF-8下，一个汉字字节使用3个字节表示
        byte[] nameBytes = name.getBytes();
        System.out.println(Arrays.toString(nameBytes));

        char[] chars1 = name.toCharArray();
        System.out.println(Arrays.toString(chars1));

        //指定下标处的字符   下标从0开始
        char c = name.charAt(3);
        System.out.println(c);

        //长度，字符个数
        System.out.println(name.length());
        for (int i = 0; i < name.length(); i++) {
            System.out.println(i + "=" + name.charAt(i));
        }

        //求字符串里的大写字母个数
        String str = "public class StringConstructor";
        int count = 0;
        for (int i = 0; i < str.length(); i++) {//要么比较码值  65：A  90：Z
            if (Character.isUpperCase(str.charAt(i))) ;
            count++;
        }
        System.out.println(count);
    }
}
